﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using cludg.Web.Core.Controllers;

namespace cludg.Web.Core.RenderHelpers
{
	public static class ViewExtensionRenderHelper
	{
		public static void ViewExtensionPlace(this HtmlHelper html, string name)
		{
			ViewExtensionPlace(html, name, html.ViewData.Model);
		}

		public static void ViewExtensionPlace(this HtmlHelper html, string name, object model)
		{
			var controller = html.ViewContext.Controller as BaseController;
			if (controller == null)
			{
				throw new ApplicationException("ViewExtensionPlace helper can be user only with BaseController objects.");
			}

			foreach (var extension in controller.ViewExtensionRegistry.Get(name))
			{
				extension.Render(html, model);
			}
		}
	}
}
